<?php

class TemperatureController extends Controller
{
	
    public function actionGetport(){
        $result = array();
        $port = array();
        exec("ComPort get",$result);
        if(!empty($result)){
            for($i=1;$i<count($result);$i++){
                $index = substr($result[$i],3);
                $port[$index] = $result[$i];
            }
            $result = json_encode(array('status'=>1,'info'=>$port,'msg'=>'获取成功'));
        }else{
            $result = json_encode(array('status'=>0,'info'=>'','msg'=>'服务器无串口'));
        }
        echo $result;
        exit();
    }
	
	
	public function actionSenddata(){
		$result = array();
        $port = array();
		$comport = $_REQUEST['comport'];
		$port_rate = $_REQUEST['port_rate'];
		$data_bit = $_REQUEST['data_bit'];
		$stop_bit = $_REQUEST['stop_bit'];
		$parity = $_REQUEST['parity'];
		$value = floatval($_REQUEST['value']);
		
		$value_string = "TC";
		if($value>0){
			$value_string .="+";
		}else{
			$value_string .="-";
		}
		$value = intval(abs($value)*10);
		if ($value < 10)
			$value_string .= "0000" .$value;
		else if ($value < 100)
			$value_string .= "000" .$value;
		else if ($value < 1000)
			$value_string .="00" .$value;
		else
			$value_string .= "0".$value;
		
		$exec_string = "ComPort $comport $port_rate $data_bit $stop_bit $parity $value_string";
        exec($exec_string,$result);
		echo $result;
		exit();
	}
    
	public function actionShow(){
	    
		$this->render('Temperature');
	}
	
	
}